home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar / 1995 / DEC / DI9512CJ / demo7u.pas < prev    next >
Pascal/Delphi Source File  |  1995-10-22  |  2KB  |  79 lines

  1. unit Demo7u;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Label1: TLabel;
  12.     Edit1: TEdit;
  13.     ComboBox1: TComboBox;
  14.     Label2: TLabel;
  15.     DataSource1: TDataSource;
  16.     Table1: TTable;
  17.     DBGrid1: TDBGrid;
  18.     CheckBox1: TCheckBox;
  19.     Button1: TButton;
  20.     CheckBox2: TCheckBox;
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure Button1Click(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. begin
  38. Table1.Open;
  39. Table1.GetFieldNames(ComboBox1.Items);
  40. ComboBox1.ItemIndex := 0;
  41. end;
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);
  44. var
  45.   GotoRecord : TBookMark;
  46. begin
  47. if Table1.State in [dsEdit,dsInsert] then
  48.   if MessageDlg('Post record?',mtConfirmation,
  49.     [mbOK,mbCancel],0) <> mrOK then
  50.     Exit
  51.   else
  52.     Table1.Post;
  53. GotoRecord := Table1.GetBookMark;
  54. Self.Cursor := crHourGlass;
  55. Table1.DisableControls;
  56. try
  57.   if not CheckBox2.Checked then
  58.     Table1.First;
  59.   while not Table1.EOF do begin
  60.     if Table1.FieldByName(ComboBox1.Text).AsString = Edit1.Text then
  61.       begin
  62.         GotoRecord := Table1.GetBookMark;
  63.         Break;
  64.       end
  65.     else
  66.       Table1.Next;
  67.   end;
  68.  
  69. finally
  70.   Table1.GotoBookMark(GotoRecord);
  71.   Table1.FreeBookMark(GotoRecord);
  72.   Table1.EnableControls;
  73.   Self.Cursor := crDefault;
  74.   DBGrid1.SetFocus;
  75. end;
  76. end;
  77.  
  78. end.
  79.